<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>活动场次页面</title>
<link rel="stylesheet"
	href="/wk1un2_electricity_digital/Backstage/layui/css/layui.css" />
</head>

<body>

	<div class="layui-form" style="margin-top: 20px;" onsubmit="false">
		<div class="layui-form-item">
			<label class="layui-form-label">场次名称</label>
			<div class="layui-input-inline">
				<input type="text" name="as_name" id="as_name" placeholder="请输入活动场名称"
					class="layui-input">
			</div>
			
			<button class="layui-btn" id="search" data-type="reload">查询</button>
		</div>
	</div>
	<table class="layui-hide" id="test" lay-filter="test"></table>
	<!--数据表格-->
	<script type="text/html" id="toolbarDemo">
			<!--表头上面引入了一个添加订单的操作-->
			<div class="layui-btn-container">
				<button class="layui-btn layui-btn-sm" lay-event="addUser">添加活动场次</button>
			</div>
		</script>
	<script type="text/html" id="barDemo">
			<!--在表格的行内加的工具-->
			<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
			<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
		</script>
	<!--检查js文件是否引入成功-->
	<script type="text/javascript"
		src="/wk1un2_electricity_digital/Backstage/layui/layui.js"></script>
	<script>
		layui.use(
						'table',
						function() {
							var table = layui.table;
							var $ = layui.jquery;
							table
									.render({
										elem : '#test',
										toolbar : '#toolbarDemo',
										url : '/wk1un2_electricity_digital/Backstage/getAllActivitySess',
										where : {
											method : 'getAll',
											as_name : ''
										},
										method : 'POST',
										cols : [ [ {
											type : "checkbox",
											fixed:'left',
											width : 50
										}, {
											field : 'as_id',
											width : 110,
											title : '场次编号',
											fixed:'left',
											sort : true,
											align : "center"
										}, {
											field : 'as_name',
											width : 150,
											title : '场次名称',
											align : "center"
										},  {
											field : 'as_time',
											width : 200,
											title : '场次时间',
											align : "center"
										},  {
											field : 'as_url',
											width : 200,
											title : '场次地址',
											align : "center"
										},     
										{
											title : '操作',
											width : 150,
											toolbar : '#barDemo',
											fixed:'right',
											align : "center"
										} ] ],
										id : 'testReload',
										page : true

									});
							//添加
							table.on('toolbar(test)', function(obj) {
								switch (obj.event) {
								case 'addUser':
									layer.open({
										type : 2,
										area : [ '500px', '500px' ],
										content : 'ActivitySess_add.jsp',
										title : '添加',
										end : function() {
											window.location.reload();
										}
									});
									break;
								}
								;
							});
							//删除
							//监听行工具事件
							table.on('tool(test)', function(obj) {
								if (obj.event === 'del') {
									layer.confirm('真的删除行么', function(index) {//删除弹框
										console.log('执行删除');
										console.log(obj.data);
										var url = '/wk1un2_electricity_digital/Backstage/deleteActivitySess';
										$.post(url, {
											"as_id" : obj.data.as_id,
											method : 'delete'
										}, function(data) {
											console.log(data);
											if (data.count > 0) {
												console.log('删除成功');
												window.location.reload();
											}
										}, "json");
									});
								} else if (obj.event === 'edit') {
									console.log(obj.data);
									layer.open({
										type : 2,
										area : [ '500px', '500px' ],
										content : 'ActivitySess_update.jsp',
										title : '编辑',//修改
										success : function(layero, index) {
											var body = layer.getChildFrame('body',index);
											body.contents().find("#as_id").val(obj.data.as_id);
											body.contents().find("#as_name").val(obj.data.as_name);							
											body.contents().find("#as_time").val(obj.data.as_time);										
											body.contents().find("#as_url").val(obj.data.as_url);			
										},
										end : function() {
											window.location.reload();
										}
									});
								}
							});
							$('#search').on('click', function() {
								var as_name = $("#as_name").val();
								
								table.reload('testReload', {//testReload,是上面渲染表格的id
									where : {//接口需要的两个请求参数
										'as_name' : as_name,
										/* 'as_id' : as_id */
									}
								});
							});
						});
					</script>
</body>


</html>